package com.garlic.face.jlf.ui;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.garlic.face.jlf.R;


/**
 * Created by shiyanqi on 18/9/18.
 */

public class CommonDialog extends Dialog{
	private String type;
	private String title;
	private String content;
	private Context context;
	private CallBack callBack;
	private CallBackTwo callBackTwo;

	public void setCallBack(CallBack callBack) {
		this.callBack = callBack;
	}

	public void setCallBackTwo(CallBackTwo callBackTwo) {
		this.callBackTwo = callBackTwo;
	}


	public CommonDialog(@NonNull Context context, String type, String title, String content) {
		super(context);
		this.context = context;
		this.type = type;
		this.title = title;
		this.content = content;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		init();
	}

	private void init() {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view;
		if (type.equals("one")){
			view = inflater.inflate(R.layout.popup_window_weight, null);
			setContentView(view);
			TextView errorTitle=view.findViewById(R.id.popup_window_error_title);
			TextView error_content=view.findViewById(R.id.popup_window_error_content);
			Button error_ok=view.findViewById(R.id.popup_window_error_ok);
			errorTitle.setText(title);
			error_content.setText(content);
			error_ok.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					callBack.oneClick(v);
				}
			});
		}else {
			view=inflater.inflate(R.layout.popup_window_confirm, null);
			setContentView(view);
			TextView confirm_title=view.findViewById(R.id.popup_window_confirm_title);
			TextView confirm_message=view.findViewById(R.id.popup_window_confirm_message);
			Button button_ok=view.findViewById(R.id.popup_window_confirm_button_ok);
			Button button_cancel=view.findViewById(R.id.popup_window_confirm_button_cancel);
			confirm_title.setText(title);
			confirm_message.setText(content);

			button_ok.setOnClickListener((v)->{
				callBackTwo.twoOk(v);
			});

			button_cancel.setOnClickListener((view1)->{
				callBackTwo.twoCancel(view1);
			});
		}
	}

	public  interface CallBack{
		void oneClick(View view);
	}

	public interface CallBackTwo{
		void twoOk(View view);
		void twoCancel(View view);
	}
}
